package core;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class StorageUnitTests
{

	private RootStorageUnit root;
	private Amount amount;
	private Amount amount2;
	private StorageUnit unit1;
	private StorageUnit unit2;
	private ProductGroup group1;
	private ProductGroup group2;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
		root = RootStorageUnit.getInstance();
		amount = new Amount(Unit.count, 0);
		unit1 = new StorageUnit("storage");
		unit2 = new StorageUnit("storage2");
		group1 = new ProductGroup("group1",amount, unit1);
		amount2 = new Amount(Unit.gallons, 5);
		group2 = new ProductGroup("group2",amount2, unit2);
	}

	@After
	public void tearDown() throws Exception
	{
	}
	
	@Test
	public void StorageUnitTest()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		assertTrue(unit1.getProductGroups()!=null);
		assertTrue(unit1.getName().compareTo("storage")==0);
	}
	
	@Test
	public void getContainerTypeTest()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		assertTrue(unit1.getContainerType() == ContainerType.STORAGE_UNIT);
		assertFalse(unit1.getContainerType() == ContainerType.PRODUCT_GROUP);
	}
	
	@Test
	public void editStorageUnitTest()
	{
		RootStorageUnit root = RootStorageUnit.getInstance();
		StorageUnit unit1 = new StorageUnit("storage");
		StorageUnit unit2 = new StorageUnit("storage2");
		ProductGroup group1 = new ProductGroup("group1",amount, unit1);
		
		unit1.editStorageUnit(unit2);
		
		assertTrue(unit1.equals(unit2));
		
		unit1.setName("editedStorage");
		assertFalse(unit1.equals(unit2));
		
		unit2.editStorageUnit(unit1);
		assertTrue(unit2.getName().compareTo("editedStorage") == 0);
		assertTrue(unit2.equals(unit1));
		
	}
	


}
